<template>
  <div style="height: 100%; width: 100%; position: relative">
    <div class="pagetop" ref="buttondiv">
      <table style="width: 100%">
        <tr>
          <td>
            <table>
              <tr>
                <td width="50" style="text-align: right">生成日期</td>
                <td width="280">
                  <el-date-picker v-model="datetime1" style="width: 46%" type="date" placeholder="开始日期"
                    value-format="yyyy-MM-dd 00:00:00" :clearable="false"></el-date-picker> 至
                  <el-date-picker v-model="datetime2" style="width: 46%" type="date" placeholder="结束日期"
                    value-format="yyyy-MM-dd 23:59:59" :clearable="false"></el-date-picker>
                </td>
                <td style="text-align: right">回单条码</td>
                <td>
                  <el-input v-model="collectbarcode"></el-input>
                </td>
                <td width="50" style="text-align: right">病历号</td>
                <td width="120">
                  <el-input v-model="patno"></el-input>
                </td>
                <td width="30" style="text-align: right">状态</td>
                <td>
                  <rm-ddl-common datatype="seccode" kindno="REQ_STAT" dataname="状态" :appendtobody="true" v-model="reqstat"
                    width="160px"></rm-ddl-common>
                </td>
                <td width="30" style="text-align: right">卡号</td>
                <td>
                  <el-input v-model="cardno" width="160px"></el-input>
                </td>
              </tr>
              <tr>
                <td width="50" style="text-align: right">送出日期</td>
                <td width="280">
                  <el-date-picker v-model="senddatetime1" style="width: 46%" type="date" placeholder="开始日期"
                    value-format="yyyy-MM-dd 00:00:00" :clearable="true"></el-date-picker> 至
                  <el-date-picker v-model="senddatetime2" style="width: 46%" type="date" placeholder="结束日期"
                    value-format="yyyy-MM-dd 23:59:59" :clearable="true"></el-date-picker>
                </td>
                <td style="text-align: right">条码号</td>
                <td width="120">
                  <el-input v-model="barcode"></el-input>
                </td>
                <td style="text-align: right">病人类型</td>
                <td>
                  <rm-ddl-common datatype="seccode" kindno="PT" dataname="病人类型" :appendtobody="true" v-model="pattype"
                    width="160px"></rm-ddl-common>
                </td>
                <td style="text-align: right">姓名</td>
                <td width="120">
                  <el-input v-model="patname"></el-input>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td>
            <table>
              <tr>
                <td width="2000px"></td>
                <td>
                  <el-button icon="el-icon-search" type="primary" @click="FindData(0)" v-has="'PINQUERY'">查询</el-button>
                </td>
                <td>
                  <el-button icon="el-icon-delete" @click="Clear()">清除</el-button>
                </td>
                <td>
                  <el-button icon="el-icon-tickets" @click="Submit()">取消送出</el-button>
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </div>
    <div class="pagecenter">
      <rm-layout-right splitcolor="#F8F8FF" movingcolor="#ccc" :splitwidth="3" :fixsize="300" :minfixsize="300">
        <div style="height: 100%">
          <vxe-table :data="tableData" :loading="loading" :keyboard-config="keyConfig"
            :keyboard-local-config="keyLocalConfig" :select-config="selectConfig" :sort-config="{ trigger: 'cell' }"
            :edit-config="{ trigger: 'click', mode: 'cell' }" @current-change="currentChangeEvent" border fit
            height="auto" header-align="center" highlight-current-row highlight-hover-row highlight-hover-column
            ref="xTable" resizable show-header-overflow="tooltip" show-overflow="tooltip" size="mini" stripe>
            <!-- <vxe-table-column type="selection" width="40" header-align="center" align="center"></vxe-table-column> -->
            <vxe-table-column :key="item.field" :field="item.field" :title="item.title" :width="item.width"
              v-for="item in tableColumn" sortable header-align="center"
              :align="item.field == 'emer_flag' ? 'center' : 'left'">
              <template v-if="item.field == 'emer_flag'" v-slot="{ row }">
                <div v-if="row.emer_flag == '1'" style="color: red">急</div>
                <div v-else></div>
              </template>
            </vxe-table-column>
          </vxe-table>
        </div>
        <template v-slot:fix>
          <div ref="xTableDiv1" style="height: 100%">
            <vxe-table :data.sync="tableDataDetail" :select-config="selectConfig" height="auto"
              :sort-config="{ trigger: 'cell' }" :loading="loadingDetail" highlight-current-row highlight-hover-row border
              fit highlight-hover-column resizable header-align="center" show-header-overflow="tooltip"
              show-overflow="tooltip" ref="xTable2" size="mini" stripe>
              <vxe-table-column :key="item.field" :field="item.field" :title="item.title" :width="item.width"
                v-for="item in tableColumnDetail" header-align="center"></vxe-table-column>
            </vxe-table>
          </div>
        </template>
      </rm-layout-right>
    </div>
  </div>
</template>

<script>
// import { parse } from "path";
export default {
  name: "REQ121",
  //以下是还未完成的功能
  //配合选项的三个申请单项目状态判断没做
  //删除his_execute中记录的his_recordid的记录，参考门诊采样当时生成的逻辑，涉及医院代码、病人类型、his_recordid联合条件
  //执行申请单计划：if gn_plan.uf_execplan_req(adc_reqid,'9',as_user,as_errmsg) < 0 then
  //同步HIS接口：IF gn_plan.uf_hisplan_add("REQSYNC_UNCREATE",adc_reqid,ls_barcode,adt_time,as_user,'条码作废同步') <> 0 THEN
  //退费HIS接口：IF gn_inter.uf_chargereq(adc_reqid,as_performby,true,as_user,adt_time,as_errmsg,ls_ret2) < 0 THEN
  data() {
    return {
      datetime1: "",
      datetime2: "",
      patname: "",
      patno: "",
      barcode: "",
      collectbarcode: "",
      pattype: "1",
      cardno: "",
      reqstat: "",

      keyConfig: {
        isDel: true,
        isTab: true,
        isEdit: true,
      },
      keyLocalConfig: {
        isArrow: true,
      },
      selectConfig: { tigger: "row" },
      loading: false,
      loadingDetail: false,
      tableData: [],
      tableDataAll: [],
      tableDataDetail: [],
      tableColumn: [],
      tableColumnDetail: [],
      interfacename: "",

      CancelVisible: false,
      reqmaster: {},
      reqitem: "",
      UpPatno: "",
      noArray: [],
      senddatetime1: "",
      senddatetime2: "",
    };
  },
  created() {
    this.InitPageData();
  },
  mounted() { },
  updated() { },
  methods: {
    currentChangeEvent({ row }) {
      this.reqmaster = row;
      this.FindDetail(row.barcode);
    },
    InitPageData() {
      var day1 = new Date();
      day1.setTime(day1.getTime());
      var s1 = day1.getFullYear() + "-" + (day1.getMonth() + 1) + "-" + day1.getDate() + " 23:59:59";
      var day2 = new Date();
      day2.setTime(day2.getTime() - 24 * 60 * 60 * 1000 * 7);
      var s2 = day2.getFullYear() + "-" + (day2.getMonth() + 1) + "-" + day2.getDate() + " 00:00:00";
      this.datetime1 = s2;
      this.datetime2 = s1;
      this.FindData(1);
      this.FindDetail("");
    },
    FindData(qtype) {
      this.loading = true;
      this.$tool
        .request({
          url: "REQ/REQ1/REQ121",
          method: "post",
          data: {
            action: "query",
            barcode: this.barcode,
            begindate: this.datetime1,
            enddate: this.datetime2,
            patno: this.patno,
            patname: this.patname,
            collectbarcode: this.collectbarcode,
            pattype: this.pattype,
            reqstat: this.reqstat,
            cardno: this.cardno,
            qtype: qtype,
            send_dt1: this.senddatetime1,
            send_dt2: this.senddatetime2,
          },
        })
        .then((res) => {
          if (res.errcode == "1") {
            this.tableColumn = res.Cols;
            this.tableData = res.Data1;
            if (res.Data1.length > 0) {
              this.$refs.xTable.setCurrentRow(res.Data1[0]);
              this.FindDetail(res.Data1[0].barcode);
            }
          } else {
            this.$alert(res.errmsg, "提示");
          }
          this.loading = false;
        });
    },
    FindDetail(barcode) {
      this.loadingDetail = true;
      this.$tool
        .request({
          url: "REQ/REQ1/REQ121",
          method: "post",
          data: {
            action: "querydetail",
            barcode: barcode,
          },
        })
        .then((res) => {
          if (res.errcode == "1") {
            this.tableColumnDetail = res.Data.Cols;
            this.tableDataDetail = res.Data.Data;
          }
          this.loadingDetail = false;
        });
    },
    Clear() {
      this.tableData = [];
      this.tableDataDetail = [];
      this.barcode = "";
      this.datetime1 = "";
      this.datetime2 = "";
      this.patname = "";
      this.patno = "";
      this.cardno = "";
      this.collectbarcode = "";
      this.reqstat = "";
    },

    Submit() {
      //var record = this.$refs.xTable.getSelectRecords();
      var record = this.$refs.xTable.getCurrentRow();
      if (record == null) {
        this.$message.error("请选择要取消送出的条码");
        return;
      }
      if (record.req_stat != "3") {
        this.$message.error("该条码状态不是【送出】状态，不能进行取消送出操作！");
        return;
      }
      this.$confirm("您确定要取消送出条码号: " + record.barcode + "  姓名: " + record.pat_name + "  的标本吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$tool
          .request({
            url: "REQ/REQ1/REQ121",
            method: "post",
            data: {
              action: "sendcancel",
              barcode: record.barcode,
            },
          })
          .then((res) => {
            if (res.flag == 1) {
              this.$message.success("取消送出成功");
              this.FindData();
            } else {
              this.$message.error("取消送出失败:" + res.msg);
            }
          });
      });
      // for (let i = 0, len = record.length; i < len; i++) {

      //}
    },
  },
};
</script>
<style scoped>
::deep .vxe-input--wrapper .vxe-input {
  height: auto;
  width: 200px;
  border-radius: 0px;
}

::deep .el-button--default.btn-custom-cancel {
  float: right !important;
  margin-left: 10px;
}

.pagetop {
  left: 0;
  right: 0;
  height: 113px;
  display: -webkit-box;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  border: solid 1px #ccc;
  position: absolute;
  z-index: 99;
}

.pagecenter {
  position: absolute;
  top: 118px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}

.middle-center {
  position: absolute;
  height: 100%;
  right: 305px;
  left: 0;
}

.middle-right {
  position: absolute;
  top: 0;
  bottom: 2px;
  width: 300px;
  right: 0px;
}

table {
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 5px;
}

::deep .el-checkbox__inner::after {
  border: 2px solid #000000 !important;
  box-sizing: content-box;
  content: "";
  border-left: 0 !important;
  border-top: 0 !important;
  height: 7px;
  left: 4px;
  position: absolute;
  top: 1px;
  transform: rotate(45deg) scaleY(0);
  width: 3px;
  transition: transform 0.15s ease-in 0.05s;
  transform-origin: center;
}

::deep .el-checkbox__input.is-disabled+span.el-checkbox__label {
  color: #000000;
  cursor: not-allowed;
}

::deep .el-checkbox__input.is-disabled .el-checkbox__inner,
.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner+.el-input.is-disabled .el-input__inner {
  background-color: #ffffff !important;
}

::deep .el-range-editor.el-input__inner {
  width: 200px;
}

::deep .el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 130px;
}</style>
